package dao.impl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import dao.GameDao;
import dbpool.DbPool;
import entity.Game;

public class GameDaoImpl implements GameDao {
	DbPool pool = DbPool.getPool();
	/*
	 * 所有游戏
	 */
	@Override
	public List<Game> selectAllGame() throws SQLException {
		Connection conn = pool.getConn();
		System.out.println(conn);
		String sql = "select * from game";
		QueryRunner runner = new QueryRunner();
		List<Game> gameList = (List<Game>) runner.query(conn, sql, new BeanListHandler<Game>(Game.class));
		pool.back(conn);
		return gameList;
	}
	/*
	 * 对应类别的游戏
	 */
	@Override
	public List<Game> selectGameByType(int type_id) throws SQLException {
		Connection conn = pool.getConn();
		System.out.println(conn);
		String sql = "select * from game where type_id = ?";
		QueryRunner runner = new QueryRunner();
		List<Game> gameList = (List<Game>) runner.query(conn, sql, new BeanListHandler<Game>(Game.class),type_id);
		pool.back(conn);
		return gameList;
	}

}
